package com.team.ai.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.team.ai.entity.User;
import com.team.ai.mapper.UserMapper;
import com.team.ai.service.CategoryService;
import com.team.ai.service.CommentsServive;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Comments/")
public class CommentsController {
    @Resource
    private RedisTemplate<String, String> redisTemplate;
    @Resource
    CommentsServive commentsServive;
    @Resource
    UserMapper userMapper;
    @SaCheckLogin
    @PostMapping("insert")
    public String insert(
            @RequestParam(value = "communityId") int communityId,
            @RequestParam(value = "comments") String comments)
    {

        int userId = StpUtil.getLoginIdAsInt();
        User user = userMapper.selectByPrimaryKey(userId);
        String uName=user.getName();
        String pic=user.getAvatar();
        return commentsServive.insert(userId,communityId,comments,uName,pic);
    }
    @GetMapping("selectList")
    public String selectList(
    ){return commentsServive.selectList();}


    @GetMapping("selectLists")
    public String selectLists(
            @RequestParam(value = "communityId") int communityId
    ){return commentsServive.selectLists(communityId);}
}
